


<!doctype html>
<html lang="zh" class="no-js">
  <head>
    
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width,initial-scale=1">
      
      
      
      <link rel="shortcut icon" href="../../images/logo.ico">
      <meta name="generator" content="mkdocs-1.1.2, mkdocs-material-5.5.3">
    
    
      
        <title>phase 模块 - spipy 使用教程</title>
      
    
    
      <link rel="stylesheet" href="../../assets/stylesheets/main.947af8d5.min.css">
      
        <link rel="stylesheet" href="../../assets/stylesheets/palette.7f672a1f.min.css">
      
      
        
        
        <meta name="theme-color" content="#009688">
      
    
    
    
      
        <link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700%7C&display=fallback">
        <style>body,input{font-family:"Roboto",-apple-system,BlinkMacSystemFont,Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"",SFMono-Regular,Consolas,Menlo,monospace}</style>
      
    
    
    
    
      
    
    
  </head>
  
  
    
    
    
    <body dir="ltr" data-md-color-scheme="" data-md-color-primary="teal" data-md-color-accent="teal">
  
    
    <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
    <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
    <label class="md-overlay" for="__drawer"></label>
    <div data-md-component="skip">
      
        
        <a href="#phasephmodel" class="md-skip">
          跳转至
        </a>
      
    </div>
    <div data-md-component="announce">
      
    </div>
    
      <header class="md-header" data-md-component="header">
  <nav class="md-header-nav md-grid" aria-label="Header">
    <a href="../.." title="spipy 使用教程" class="md-header-nav__button md-logo" aria-label="spipy 使用教程">
      
  <img src="../../images/logo.png" alt="logo">

    </a>
    <label class="md-header-nav__button md-icon" for="__drawer">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2z"/></svg>
    </label>
    <div class="md-header-nav__title" data-md-component="header-title">
      
        <div class="md-header-nav__ellipsis">
          <span class="md-header-nav__topic md-ellipsis">
            spipy 使用教程
          </span>
          <span class="md-header-nav__topic md-ellipsis">
            
              phase 模块
            
          </span>
        </div>
      
    </div>
    
      <label class="md-header-nav__button md-icon" for="__search">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0116 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 019.5 16 6.5 6.5 0 013 9.5 6.5 6.5 0 019.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5z"/></svg>
      </label>
      
<div class="md-search" data-md-component="search" role="dialog">
  <label class="md-search__overlay" for="__search"></label>
  <div class="md-search__inner" role="search">
    <form class="md-search__form" name="search">
      <input type="text" class="md-search__input" name="query" aria-label="搜索" placeholder="搜索" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" data-md-state="active">
      <label class="md-search__icon md-icon" for="__search">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0116 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 019.5 16 6.5 6.5 0 013 9.5 6.5 6.5 0 019.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5z"/></svg>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
      </label>
      <button type="reset" class="md-search__icon md-icon" aria-label="Clear" data-md-component="search-reset" tabindex="-1">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/></svg>
      </button>
    </form>
    <div class="md-search__output">
      <div class="md-search__scrollwrap" data-md-scrollfix>
        <div class="md-search-result" data-md-component="search-result">
          <div class="md-search-result__meta">
            Initializing search
          </div>
          <ol class="md-search-result__list"></ol>
        </div>
      </div>
    </div>
  </div>
</div>
    
    
  </nav>
</header>
    
    <div class="md-container" data-md-component="container">
      
        
      
      
        
      
      <main class="md-main" data-md-component="main">
        <div class="md-main__inner md-grid">
          
            
              <div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    <nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
  <label class="md-nav__title" for="__drawer">
    <a href="../.." title="spipy 使用教程" class="md-nav__button md-logo" aria-label="spipy 使用教程">
      
  <img src="../../images/logo.png" alt="logo">

    </a>
    spipy 使用教程
  </label>
  
  <ul class="md-nav__list" data-md-scrollfix>
    
      
      
      


  <li class="md-nav__item">
    <a href="../.." title="简介" class="md-nav__link">
      简介
    </a>
  </li>

    
      
      
      


  <li class="md-nav__item md-nav__item--nested">
    
      <input class="md-nav__toggle md-toggle" data-md-toggle="nav-2" type="checkbox" id="nav-2">
    
    <label class="md-nav__link" for="nav-2">
      快速上手
      <span class="md-nav__icon md-icon">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M8.59 16.58L13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.42z"/></svg>
      </span>
    </label>
    <nav class="md-nav" aria-label="快速上手" data-md-level="1">
      <label class="md-nav__title" for="nav-2">
        <span class="md-nav__icon md-icon">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
        </span>
        快速上手
      </label>
      <ul class="md-nav__list" data-md-scrollfix>
        
        
          
          
          


  <li class="md-nav__item">
    <a href="../../Getting-Started/installation/" title="安装" class="md-nav__link">
      安装
    </a>
  </li>

        
          
          
          


  <li class="md-nav__item">
    <a href="../../Getting-Started/framework/" title="模块架构" class="md-nav__link">
      模块架构
    </a>
  </li>

        
          
          
          


  <li class="md-nav__item">
    <a href="../../Getting-Started/best-practice/" title="使用例子" class="md-nav__link">
      使用例子
    </a>
  </li>

        
      </ul>
    </nav>
  </li>

    
      
      
      


  <li class="md-nav__item md-nav__item--nested">
    
      <input class="md-nav__toggle md-toggle" data-md-toggle="nav-3" type="checkbox" id="nav-3">
    
    <label class="md-nav__link" for="nav-3">
      命令行工具
      <span class="md-nav__icon md-icon">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M8.59 16.58L13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.42z"/></svg>
      </span>
    </label>
    <nav class="md-nav" aria-label="命令行工具" data-md-level="1">
      <label class="md-nav__title" for="nav-3">
        <span class="md-nav__icon md-icon">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
        </span>
        命令行工具
      </label>
      <ul class="md-nav__list" data-md-scrollfix>
        
        
          
          
          


  <li class="md-nav__item">
    <a href="../../Scripts/Introduction/" title="简介" class="md-nav__link">
      简介
    </a>
  </li>

        
          
          
          


  <li class="md-nav__item">
    <a href="../../Scripts/Integrated-UI/" title="集成可视化工具" class="md-nav__link">
      集成可视化工具
    </a>
  </li>

        
      </ul>
    </nav>
  </li>

    
      
      
      

  


  <li class="md-nav__item md-nav__item--active md-nav__item--nested">
    
      <input class="md-nav__toggle md-toggle" data-md-toggle="nav-4" type="checkbox" id="nav-4" checked>
    
    <label class="md-nav__link" for="nav-4">
      API文档
      <span class="md-nav__icon md-icon">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M8.59 16.58L13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.42z"/></svg>
      </span>
    </label>
    <nav class="md-nav" aria-label="API文档" data-md-level="1">
      <label class="md-nav__title" for="nav-4">
        <span class="md-nav__icon md-icon">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
        </span>
        API文档
      </label>
      <ul class="md-nav__list" data-md-scrollfix>
        
        
          
          
          


  <li class="md-nav__item">
    <a href="../analyse/" title="analyse模块" class="md-nav__link">
      analyse模块
    </a>
  </li>

        
          
          
          


  <li class="md-nav__item">
    <a href="../image/" title="image模块" class="md-nav__link">
      image模块
    </a>
  </li>

        
          
          
          


  <li class="md-nav__item">
    <a href="../merge/" title="merge模块" class="md-nav__link">
      merge模块
    </a>
  </li>

        
          
          
          

  


  <li class="md-nav__item md-nav__item--active">
    
    <input class="md-nav__toggle md-toggle" data-md-toggle="toc" type="checkbox" id="__toc">
    
    
      <label class="md-nav__link md-nav__link--active" for="__toc">
        phase模块
        <span class="md-nav__icon md-icon">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 9h14V7H3v2m0 4h14v-2H3v2m0 4h14v-2H3v2m16 0h2v-2h-2v2m0-10v2h2V7h-2m0 6h2v-2h-2v2z"/></svg>
        </span>
      </label>
    
    <a href="./" title="phase模块" class="md-nav__link md-nav__link--active">
      phase模块
    </a>
    
      
<nav class="md-nav md-nav--secondary" aria-label="目录">
  
  
  
    <label class="md-nav__title" for="__toc">
      <span class="md-nav__icon md-icon">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
      </span>
      目录
    </label>
    <ul class="md-nav__list" data-md-scrollfix>
      
        <li class="md-nav__item">
  <a href="#phasephmodel" class="md-nav__link">
    phase.phmodel
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#phasephexec" class="md-nav__link">
    phase.phexec
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#phasephase2d" class="md-nav__link">
    phase.phase2d （停止维护）
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#phasephase3d" class="md-nav__link">
    phase.phase3d （停止维护）
  </a>
  
</li>
      
    </ul>
  
</nav>
    
  </li>

        
          
          
          


  <li class="md-nav__item">
    <a href="../simulate/" title="simulate模块" class="md-nav__link">
      simulate模块
    </a>
  </li>

        
      </ul>
    </nav>
  </li>

    
      
      
      


  <li class="md-nav__item md-nav__item--nested">
    
      <input class="md-nav__toggle md-toggle" data-md-toggle="nav-5" type="checkbox" id="nav-5">
    
    <label class="md-nav__link" for="nav-5">
      图形界面
      <span class="md-nav__icon md-icon">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M8.59 16.58L13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.42z"/></svg>
      </span>
    </label>
    <nav class="md-nav" aria-label="图形界面" data-md-level="1">
      <label class="md-nav__title" for="nav-5">
        <span class="md-nav__icon md-icon">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
        </span>
        图形界面
      </label>
      <ul class="md-nav__list" data-md-scrollfix>
        
        
          
          
          


  <li class="md-nav__item">
    <a href="../../Graphics-UI/installation/" title="安装" class="md-nav__link">
      安装
    </a>
  </li>

        
          
          
          


  <li class="md-nav__item">
    <a href="../../Graphics-UI/preview/" title="预览" class="md-nav__link">
      预览
    </a>
  </li>

        
      </ul>
    </nav>
  </li>

    
  </ul>
</nav>
                  </div>
                </div>
              </div>
            
            
              <div class="md-sidebar md-sidebar--secondary" data-md-component="toc">
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    
<nav class="md-nav md-nav--secondary" aria-label="目录">
  
  
  
    <label class="md-nav__title" for="__toc">
      <span class="md-nav__icon md-icon">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
      </span>
      目录
    </label>
    <ul class="md-nav__list" data-md-scrollfix>
      
        <li class="md-nav__item">
  <a href="#phasephmodel" class="md-nav__link">
    phase.phmodel
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#phasephexec" class="md-nav__link">
    phase.phexec
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#phasephase2d" class="md-nav__link">
    phase.phase2d （停止维护）
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#phasephase3d" class="md-nav__link">
    phase.phase3d （停止维护）
  </a>
  
</li>
      
    </ul>
  
</nav>
                  </div>
                </div>
              </div>
            
          
          <div class="md-content">
            <article class="md-content__inner md-typeset">
              
                
                
                  
                
                
                  <h1>phase模块</h1>
                
                <p><strong>Phase Retrieval Network Framework (Suggested)</strong></p>
<p>In this framework, you can use different algorithms to build a phasing network, just like building a neural network using pytorch. Here every <strong>node</strong> contains an algorithm and the <strong>data stream</strong> goes through all of the nodes in your specified order. The framework supports multiple input nodes and single output node. It could do phasing of both <strong>2D pattern</strong> and <strong>3D volume</strong> inputs.</p>
<p>Now the framework contains <strong>ERA</strong> / <strong>HIO</strong> / <strong>DM</strong> / <strong>RAAR</strong> / <strong>HPR</strong> algorithms. More methods are under design and will be released later. See an example network below for a straight forward look.</p>
<p><img alt="example" src="../../images/PRNF-example.png" /></p>
<h3 id="phasephmodel">phase.phmodel</h3>
<p><strong>NOTE-1</strong> : All of the classes in 'phmodel' module has a 'run' function, which will be called by <strong>phexec.Runner</strong> to run a node, please do not change it.</p>
<p><strong>NOTE-2</strong> : Every instance of classes in 'phmodel' has an 'id' attribute, which is the identical number of a node in the network.</p>
<pre><code>Parameter_dict_template = 
{
    # input diffraction intensity (both 2D and 3D data are fine)
    &quot;pattern_path&quot; : xxx.npy,

    # input mask (masked pixel is 1, unmasked pixel is 0)
    &quot;mask_path&quot; : xxx.npy,

    # radius of central mask, set None to ignore
    &quot;center_mask&quot; : 5,

    # inside and outside radius of a ring area to be masked, set None to ignore
    &quot;edge_mask&quot; : [60,64],

    # inside and outside radius of a ring area where pattern pixels will be set to 0, set None to ignore
    &quot;edge_remove&quot; : None,

    # subtract input pattern by a percentile of itself, a float within (0,1), set False to ignore
    &quot;subtract_percentile&quot; : False,

    # radius of a fixed circle support, set None to ignore
    &quot;fixed_support_r&quot; : 10,

    # whether to fit backgound in phasing
    &quot;background&quot; : True,

    # the initial model, set None to use random initiaion
    &quot;initial_model&quot; : xxx.npy
}
</code></pre>

<ul>
<li>
<p>class <strong>pInput</strong> : input node of a phasing network</p>
<ul>
<li>
<p>__init__ (self, config_dict, name=None)</p>
<ul>
<li><code>config_dict</code> : parameter dict, refer to the template above</li>
<li><code>name</code> : name of this node, default is class name</li>
</ul>
<p>[<strong>return</strong>] self. The 'pInput' nodes should be the first layer of network and thus they don't have 'after' function.</p>
</li>
</ul>
</li>
<li>
<p>class <strong>pOutput</strong> : output node of a phasing network</p>
<ul>
<li>__init__ (self, name=None)<ul>
<li><code>name</code> : name of this node, default is class name</li>
</ul>
</li>
<li>
<p>after (self, father_node)</p>
<ul>
<li><code>father_node</code> : add father of this node</li>
</ul>
<p>[<strong>return</strong>] self. You can use this function for serval times to add multiple fathers to this node. Importantly, 'pOutput' node could not be father of any nodes.</p>
</li>
</ul>
</li>
<li>
<p>class <strong>pMerge</strong> : doing average to data streams from father nodes</p>
<ul>
<li>__init__ (self, name=None)<ul>
<li><code>name</code> : name of this node, default is class name</li>
</ul>
</li>
<li>
<p>after (self, father_node)</p>
<ul>
<li><code>father_node</code> : add father to this node</li>
</ul>
<p>[<strong>return</strong>] self. You can use this function for serval times to add multiple fathers to this node.</p>
</li>
</ul>
</li>
<li>
<p>class <strong>ERA</strong> : "Error Reduction" algorithm node</p>
<ul>
<li>__init__ (self, iteration, support_size, name=None)<ul>
<li><code>iteration</code> : how many iterations for ERA to run, int</li>
<li><code>support_size</code> : (estimated) number of pixels within final retrieved support, int</li>
<li><code>name</code> : name of this node, default is class name</li>
</ul>
</li>
<li>
<p>after (self, father_node)</p>
<ul>
<li><code>father_node</code> : add a father to this node</li>
</ul>
<p>[<strong>return</strong>] self. You can use this function for serval times to add multiple fathers to this node.</p>
</li>
</ul>
</li>
<li>
<p>class <strong>DM</strong> : "Difference Map" algorithm node</p>
<ul>
<li>__init__ (self, iteration, support_size, name=None)<ul>
<li>the same with ERA</li>
</ul>
</li>
<li>
<p>after (self, father_node)</p>
<ul>
<li><code>father_node</code> : add a father to this node</li>
</ul>
<p>[<strong>return</strong>] self. You can use this function for serval times to add multiple fathers to this node.</p>
</li>
</ul>
</li>
<li>
<p>class <strong>RAAR</strong> : RAAR algorithm node</p>
<ul>
<li>__init__ (self, iteration, support_size, beta, name=None)<ul>
<li><code>beta</code> : a float from [0,1]. If beta==0, then RAAR degenerate to ERA</li>
<li>others are same with ERA</li>
</ul>
</li>
<li>
<p>after (self, father_node)</p>
<ul>
<li><code>father_node</code> : add a father to this node</li>
</ul>
<p>[<strong>return</strong>] self. You can use this function for serval times to add multiple father to this node.</p>
</li>
</ul>
</li>
<li>
<p>class <strong>HIO</strong> : "Hybrid Input Output" algorithm node</p>
<ul>
<li>__init__ (self, iteration, support_size,  gamma, name=None)<ul>
<li><code>gamma</code> : greedy rate, a float from (0,1]. If gamma==1, then HIO degenerate to ERA</li>
<li>others are same with ERA</li>
</ul>
</li>
<li>
<p>after (self, father_node)</p>
<ul>
<li><code>father_node</code> : add a father to this node</li>
</ul>
<p>[<strong>return</strong>] self. You can use this function for serval times to add multiple father to this node.</p>
</li>
</ul>
</li>
<li>
<p>class <strong>HPR</strong> : "Hybrid projectopn restriction" algorithm node</p>
<ul>
<li>__init__ (self, iteration, support_size, gamma, hprcoff=0.5, name=None)<ul>
<li><code>gamma</code> : greedy rate, a float from (0,1]. If gamma==1, then HPR degenerate to ERA</li>
<li><code>hprcoff</code> : the threshold of overlapping rate (R_v) between retrieved supports of previous and this iterations, a float within (0,1). If R_v&gt;hprcoff then use HPR algorithm, otherwise apply HIO algorithm.</li>
<li>others are same with ERA</li>
</ul>
</li>
<li>
<p>after (self, father_node)</p>
<ul>
<li><code>father_node</code> : add a father to this node</li>
</ul>
<p>[<strong>return</strong>] self. You can use this function for serval times to add multiple fathers to this node.</p>
</li>
</ul>
</li>
</ul>
<h3 id="phasephexec">phase.phexec</h3>
<ul>
<li>
<p>class <strong>Runner</strong> : running phasing network, support mpi4py parallel</p>
<ul>
<li>
<p>__init__ (self, inputnodes = None, outputnode = None, loadfile = None, reload_dataset = None, comm = None)</p>
<ul>
<li><code>inputnodes</code> : a list of "pInput" instances, the input nodes of the whole network</li>
<li><code>outputnode</code> : one "pOutput" instance, the output node of the network</li>
<li><code>loadfile</code> : str, file path, load network from this json file</li>
<li><code>reload_dataset</code> : a dict, {input_node_id : {"pattern_path" : "xxx.npy", "mask_path" : "xxx.npy" or None, "initial_model" : "xxx.npy" or None}, ...}. The input data stream will be reloaded. Only valid when 'loadfile' is given. Necessary when 'loadfile' is a skeleton network file.</li>
<li><code>comm</code> : communicator of MPI ranks. If you use mpi4py, please provide this variable. Default is None.</li>
</ul>
<p>[<strong>NOTE</strong>] You can specify either <code>inputnode</code> + <code>outputnode</code> or <code>loadfile</code> + <code>reload_dataset</code> to initiate a Runner.</p>
</li>
<li>
<p>run (self, repeat=1)</p>
<ul>
<li><code>repeat</code> : times of independent phasing <strong>of single mpi rank</strong>, int</li>
</ul>
<p>[<strong>return</strong>] phasing results, a dict containning keys : ["sample_ret", "support", "PRTF", "background", "eMod", "eCon", "stream_path", "diffraction_amp"], <strong>only</strong> rank-0 process will return results.</p>
</li>
<li>
<p>dump_model (self, model_file, skeleton = False)</p>
<ul>
<li><code>model_file</code> : str, file path to save this phasing network</li>
<li><code>skeleton</code> : bool, whether to save input data stream of this network, save (False) or not save (True)</li>
</ul>
<p>[<strong>return</strong>] A file will be generated to describe the network you created. You can share this file to others to build a same network.</p>
</li>
<li>
<p>save_h5 (self, out, save_file)</p>
<ul>
<li><code>out</code> : a dict, the phasing results from 'Runner.run' function</li>
<li><code>save_file</code> : save results to a specific HDF5 file</li>
</ul>
</li>
<li>
<p>plot_result (self, out)</p>
<ul>
<li><code>out</code> : a dict, the phasing results from 'Runner.run' function</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><strong>--- Programming example to build a network model like the figure above ---</strong></p>
<pre><code class="python"># Examles of using PRNF programming,
# you can find more at &quot;spipy/test_spipy/phase/test_phmodel.py&quot;

import numpy as np
from spipy.phase import phexec, phmodel

from mpi4py import MPI
comm = MPI.COMM_WORLD
mrank = comm.Get_rank()
msize = comm.Get_size()

if __name__ == &quot;__main__&quot;:

    config_input = {
        &quot;pattern_path&quot; : &quot;pattern.npy&quot;,
        &quot;mask_path&quot; : &quot;pat_mask.npy&quot;,
        &quot;center_mask&quot; : 5,
        &quot;edge_mask&quot; : None,
        &quot;subtract_percentile&quot; : False,
        &quot;fixed_support_r&quot; : None,
        &quot;background&quot; : True,
        &quot;initial_model&quot; : None
    }
    iters = [150,100,200]
    support_size = 85
    beta = 0.8
    gamma = 0.05
    newdataset = {&quot;pattern_path&quot; : &quot;pattern.npy&quot;, &quot;mask_path&quot; : &quot;pat_mask.npy&quot;, &quot;initial_model&quot; : None}

    # set up network
    l1_0 = phmodel.pInput(config_input)
    l1_1 = phmodel.pInput(config_input)
    l2_0 = phmodel.HIO(iters[0], support_size, gamma).after(l1_0)
    l2_1 = phmodel.ERA(iters[0], support_size).after(l1_1)
    l2_2 = phmodel.RAAR(iters[0], support_size, beta).after(l1_1)
    lm = phmodel.pMerge().after(l2_0).after(l2_1).after(l2_2)
    l4 = phmodel.DM(iters[1], support_size).after(lm)
    l5 = phmodel.HIO(iters[2], support_size, gamma).after(l4)
    l6 = phmodel.pOutput().after(l5)

    # run
    runner = phexec.Runner(inputnodes = [l1_0, l1_1], outputnode = l6, comm=comm)
    out = runner.run(repeat = 2)

    if mrank == 0:
        runner.plot_result(out)

    # Dump network
    runner.dump_model(&quot;temp_model.json&quot;, skeleton=False)

    # Reload network
    runner2 = phexec.Runner(inputnodes = None, outputnode = None, \
        loadfile = &quot;temp_model.json&quot;, reload_dataset = {l1_0.id:newdataset}, comm=comm)
    out = runner2.run(repeat = 1)
</code></pre>

<hr />
<p><strong>Functional based phase retrieval program (deprecated)</strong></p>
<ul>
<li><em>Phase retrieval algorithms</em> :<ul>
<li><em>ER (error reduction)</em></li>
<li><em>DM (difference map)</em></li>
<li><em>RAAR (relaxed averaged alternating reflections)</em></li>
</ul>
</li>
</ul>
<h3 id="phasephase2d">phase.phase2d （停止维护）</h3>
<p>-&gt; <em>2d pattern phase retrieval</em></p>
<pre><code class="ini"># 2d phase retrieval basic parameters
- 'input|shape' : input pattern shape, default='123,123'

- 'input|padd_to_pow2' : zero padding to make the size of pattern to be a 2^n number, default=True

- 'input|inner_mask' : pixels whose radius&lt;inner_mask are allowed to float while phasing, default=5

- 'input|outer_mask' : pixels whose radius&gt;outer_mask are set to zero, default=64

- 'input|outer_outer_mask' : pixels whose radius are between outer_mask and outer_outer_mask are allowed to float, default=None

- 'input|mask_edges' : bool, whether allow pixels between outer_mask and outer_outer_mask to float, default=True

- 'phasing|repeats' : how many times of independent phasing for **every process**, default=40

- 'phasing|iters' : schedual iterations for 1 phasing loop, default is '100RAAR 200DM 200ERA' which means '100 times RAAR algorithm -&gt; 200 times DM algorithm -&gt; 200 times ER algorithm'

- 'phasing_parameters|support_size' : set restriction to the number of pixels inside final support of shrinkwrap process, default=200

- 'phasing_parameters|beta' : beta value for RAAR algorithm, float from 0 to 1, default=0.8

# 2d phase retrieval advanced parameters
- 'input|subtract_percentile' : subtract the X percentile value of data for all pixels, float value from 0 to 100, default=None

- 'input|spherical_support' : radius of spherical support that added at the initiation, default=None

- 'input|init_model' : filepath of initial REAL space model. Support .npy, .bin and .mat file formats. The size of init model should agree with 'input|shape' after 'input|padd_2_pow', default=None

- 'phasing_parameters|background' : evaluate background while phasing, default=True
</code></pre>

<h3 id="phasephase3d">phase.phase3d （停止维护）</h3>
<p>-&gt; <em>3d volume phase retrieval</em></p>
<pre><code class="ini"># 3d phase retrieval basic parameters
- 'input|shape' : input pattern shape, default='120,120,120'

- 'input|padd_to_pow2' : zero padding to make the size of pattern to be a 2^n number, default=True

- 'input|inner_mask' : pixels whose radius&lt;inner_mask are allowed to float while phasing, default=3

- 'input|outer_mask' : pixels whose radius&gt;outer_mask are set to zero, default=64

- 'input|outer_outer_mask' : pixels whose radius are between outer_mask and outer_outer_mask are allowed to float, default=None

- 'input|mask_edges' : bool, whether allow pixels between outer_mask and outer_outer_mask to float, default=False

- 'phasing|repeats' : how many times of independent phasing for **every process**, default=40

- 'phasing|iters' : schedual iterations for 1 phasing loop, default is '100RAAR 200DM 200ERA' which means '100 times RAAR algorithm -&gt; 200 times DM algorithm -&gt; 200 times ER algorithm'

- 'phasing_parameters|voxel_number' : set restriction to the number of pixels inside final support of shrinkwrap process, default=2000

- 'phasing_parameters|beta' : beta value for RAAR algorithm, float from 0 to 1, default=0.8

# 3d phase retrieval advanced parameters
- 'input|subtract_percentile' : subtract the X percentile value of data for all pixels, float value from 0 to 100, default=None

- 'input|spherical_support' : radius of spherical support that added at the initiation, default=None

- 'input|init_model' : filepath of initial REAL space model. Support .npy, .bin and .mat file formats. The size of init model should agree with 'input|shape' after 'input|padd_2_pow', default=None

- 'phasing_parameters|background' : evaluate background while phasing, default=True
</code></pre>

<p><strong>phase.phase3d and phase.phase2d have same <em>APIs</em></strong> : </p>
<ul>
<li>
<p><strong>new_project</strong> (data_path, mask_path=None, path=None, name=None)</p>
<ul>
<li><code>data_path</code> : path of your original diffraction data, support '.npy' or '.mat', or '.bin' files. For '.bin' file, dtype should be <em>float</em></li>
<li><code>mask_path</code> : path of user-defined mask file, a 0/1 numpy array where 1 means masked point</li>
<li><code>path</code> : create work directory under this path, set None to use current dir</li>
<li><code>name</code> : give a name to your project, set None to let program choose one for you</li>
</ul>
<p>[<strong>return</strong>] create project, no return</p>
</li>
<li>
<p><strong>config_project</strong> (params)</p>
<ul>
<li><code>params</code> : dict, parameters (see above) to configure</li>
</ul>
<p>[<strong>return</strong>] configuration, no return</p>
</li>
<li>
<p><strong>run_project</strong> (num_proc=1, nohup=False, cluster=False)</p>
<ul>
<li><code>num_proc</code> : int, this function maps multi-processes automatically, so you need to figure out how many processes to run in parallel</li>
<li><code>nohup</code> : bool, whether run in background</li>
<li><code>cluster</code> : bool, whether you will submit jobs using job scheduling system, if True, the function will only generate a command file at your work path without submitting it; if False, the program will run directly</li>
</ul>
<p>[<strong>return</strong>] start phase retrieval, no return</p>
</li>
<li>
<p><strong>use_project</strong> (project_path)</p>
<ul>
<li><code>project_path</code> : string, the path of project directory that you want to switch to</li>
</ul>
<p>[<strong>return</strong>] switch to a existing project, no return</p>
</li>
</ul>
                
                  
                
              
              
                


              
            </article>
          </div>
        </div>
      </main>
      
        
<footer class="md-footer">
  
    <div class="md-footer-nav">
      <nav class="md-footer-nav__inner md-grid" aria-label="Footer">
        
          <a href="../merge/" title="merge模块" class="md-footer-nav__link md-footer-nav__link--prev" rel="prev">
            <div class="md-footer-nav__button md-icon">
              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
            </div>
            <div class="md-footer-nav__title">
              <div class="md-ellipsis">
                <span class="md-footer-nav__direction">
                  上一页
                </span>
                merge模块
              </div>
            </div>
          </a>
        
        
          <a href="../simulate/" title="simulate模块" class="md-footer-nav__link md-footer-nav__link--next" rel="next">
            <div class="md-footer-nav__title">
              <div class="md-ellipsis">
                <span class="md-footer-nav__direction">
                  下一页
                </span>
                simulate模块
              </div>
            </div>
            <div class="md-footer-nav__button md-icon">
              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 11v2h12l-5.5 5.5 1.42 1.42L19.84 12l-7.92-7.92L10.5 5.5 16 11H4z"/></svg>
            </div>
          </a>
        
      </nav>
    </div>
  
  <div class="md-footer-meta md-typeset">
    <div class="md-footer-meta__inner md-grid">
      <div class="md-footer-copyright">
        
        Made with
        <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
          Material for MkDocs
        </a>
      </div>
      
    </div>
  </div>
</footer>
      
    </div>
    
      <script src="../../assets/javascripts/vendor.c3dc8c49.min.js"></script>
      <script src="../../assets/javascripts/bundle.f9edbbd5.min.js"></script><script id="__lang" type="application/json">{"clipboard.copy": "\u590d\u5236", "clipboard.copied": "\u5df2\u590d\u5236", "search.config.lang": "ja", "search.config.pipeline": "trimmer, stemmer", "search.config.separator": "[\\uff0c\\u3002]+", "search.result.placeholder": "\u952e\u5165\u4ee5\u5f00\u59cb\u641c\u7d22", "search.result.none": "\u6ca1\u6709\u627e\u5230\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.one": "\u627e\u5230 1 \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.other": "# \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c"}</script>
      
      <script>
        app = initialize({
          base: "../..",
          features: [],
          search: Object.assign({
            worker: "../../assets/javascripts/worker/search.8e2cddea.min.js"
          }, typeof search !== "undefined" && search)
        })
      </script>
      
    
  </body>
</html>